import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    // vueDevTools(),
    Components({
      resolvers: [VantResolver()]   // ← 自动帮你引入组件+样式
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    port: 5173,
    host: true, // 允许从外部访问
    proxy: {
      '/api': {
        target: 'http://localhost:8080',
        // target: 'https://86nd0oq76653.vicp.fun:443',
        changeOrigin: true, // 支持跨域
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  },
})
